package com.ruoyi.project.opencv.base;


import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.project.opencv.common.utils.Base64Util;
import com.ruoyi.project.opencv.common.utils.FileUtil;
import com.ruoyi.project.opencv.common.utils.HttpUtil;
import sun.misc.Unsafe;

import javax.security.auth.callback.Callback;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 通用文字识别（高精度版）
 */
public class AccurateBasic {

    /**
     * 重要提示代码中所需工具类
     * FileUtil,Base64Util,HttpUtil,GsonUtils请从
     * https://ai.baidu.com/file/658A35ABAB2D404FBF903F64D47C1F72
     * https://ai.baidu.com/file/C8D81F3301E24D2892968F09AE1AD6E2
     * https://ai.baidu.com/file/544D677F5D4E4F17B4122FBD60DB82B3
     * https://ai.baidu.com/file/470B3ACCA3FE43788B5A963BF0B625F3
     * 下载
     */
    public static String accurateBasic() {
        // 请求url
        String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic";
        try {
            // 本地文件路径
            String filePath = "C:\\Users\\admin\\Desktop\\test.jpg";
//            String filePath = "E:\\ftp图片\\a.png";
            byte[] imgData = FileUtil.readFileByBytes(filePath);
            String imgStr = Base64Util.encode(imgData);
            String imgParam = URLEncoder.encode(imgStr, "UTF-8");

            String param = "image=" + imgParam;

            // 注意这里仅为了简化编码每一次请求都去获取access_token，线上环境access_token有过期时间， 客户端可自行缓存，过期后重新获取。
            String accessToken = AuthService.getAuth("aiVAKPIjp4ojfnvIcZkFwEB0","f7qCbsuiuYoVWttPX93ctveDgyARROoM");

            String result = HttpUtil.post(url, accessToken, param);
            System.out.println(result);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static final String B = "123456";

    public static String getB() {
        return B;
    }

    public static Long po = System.currentTimeMillis();

    
    private static class AccurateBasicHolder{
        private static final AccurateBasic INSTANCE = new AccurateBasic();
        private AccurateBasicHolder(){}
        private static final AccurateBasic getInstace(){
            return AccurateBasicHolder.INSTANCE;
        }
    }


//    public static int binarySearch(int[] arr,int start,int end,int key){
//        int mid = start+(end-start)/2;
//        if (start<end){
//            if (arr[mid]==key){
//                return 1;
//            }else if (key>arr[mid]){
//                return binarySearch(arr,mid+1,end,key);
//            }else if (key<arr[mid]){
//                return binarySearch(arr,start,mid-1,key);
//            }
//        }
//        return -1;
//    }

    public static int fun(int m){
        if(m<2){
            return 1;
        }else{
            return fun(m - 1)+fun(m-2);
        }
    }

    /*public static int binarySearch(int[] arr,int key,int start,int end){
        int mid = start+(end-start)/2;
        if (arr[mid]==key){
            return mid;
        }else if (arr[mid]>key){
            return binarySearch(arr,key,start,mid-1);
        }else {
            return binarySearch(arr,key,mid+1,end);
        }
    }*/

    public static void quick(int[] arr,int l ,int r){

    }

    public static int[] partition(int[] arr,int l ,int r){
        //announce two pointer
        int less = l-1;
        int more = r;
        while (l<more){
            if (arr[l]<arr[r]){
                swap(arr,++less,l++);
            }
        }
        return arr;
    }

    public static void swap(int[] arr,int l,int r){
        int temp = arr[l];
        arr[l] = arr[r];
        arr[r] = temp;
    }

    public static void main(String[] args) {

        /*String a = "123456";
        String b = a.intern();
        System.out.println("b变量的打印："+b);
        System.out.println("常量B的引用地址："+AccurateBasic.B.hashCode()+"    临时a变量的引用地址："+a.hashCode());*/

//        AccurateBasic.accurateBasic();
        /*List<String> list = new LinkedList<>();
        List<String> list1 = new ArrayList<>();
        HashMap<String,String> map = new HashMap<>();
        System.out.println("没改变之前的po："+po);
        po = System.currentTimeMillis();
        System.out.println("改变之后的po："+po);
        int aa = 2;
        int bb = 5;
        int temp = (int)(Math.random()*(100+1));
        System.out.println(temp);
        System.out.println(fun(12));
        map.put("123","123");
        String tt = map.put("123","456");
        System.out.println(tt);
        System.out.println(map.get("123"));
        int[] arr = {12,987,46,64,6741,3,1,45,179,97,54,96,84};
        swap(arr,0,1);
        System.out.println("打印交换后的数组："+Arrays.toString(arr));

        String format = "yyyy-MM-dd HH:mm:ss";
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        Calendar date = Calendar.getInstance();
        date.setTime(new Date());
        date.add(Calendar.MINUTE, -10);
        String fireTime = sdf.format(date.getTime());
        System.out.println("打印的时间："+fireTime);*/
        accurateBasic();
    }
}
